<script>
	import contact from '@/utils/contact.js'
	// #ifdef H5	
	// 微信快速登录
	import {
		isWxClient
	} from '@/utils/utils.js'
	import {
		loginWxClient
	} from '@/utils/login_wx_client.js'
	import isBindOfThird from '@/utils/isBindOfThird.js'
	// #endif

	export default {
		globalData: {
			menuBottom: 0, // 胶囊距底部间距
			menuHeight: 0, // 胶囊高度
			statusBarHeight: 0, // 状态栏高度
			navBarHeight: 0, // 导航栏高度
			stickyHeight: 0, // 导航栏高度 + 状态栏高度
		},
		onLaunch: function() {
			
			
			// #ifdef MP-WEIXIN || MP-BAIDU || MP-TOUTIAO

			//小程序后台->设置 小程序最低可用版本才可生效
			const updateManager = uni.getUpdateManager();
			updateManager.onCheckForUpdate(function(res) {
				if (res.hasUpdate) {
					updateManager.onUpdateReady(function(res) {
						uni.showModal({
							title: '更新提示',
							content: '新版本已经准备好，是否重启应用？',
							success(res) {
								if (res.confirm) {
									// 新的版本已经下载好，调用 applyUpdate 应用新版本并重启
									updateManager.applyUpdate();
								}
							}
						});
					});
				}
			});


			// #endif

			// #ifdef H5			
			// 微信快速登录		
			loginWxClient(this);
			// 设置微信字体
			this.initFontSize()

			isBindOfThird();
			// #endif

			this.$getApp();

			// 电话客服
			contact();

			// #ifdef MP-TOUTIAO
			// 抖音小程序退款样式
			this.getThemeConfig();
			// #endif

			//获取系统数据
			this.systemInfo();

			let userInfo = uni.getStorageSync('userInfo');
			if (userInfo) {
				this.$store.commit('login', userInfo)
			}
		},
		onShow: function(e) {
			
		},
		onHide: function() {

		},
		methods: {
			

			// #ifdef H5

			// 设置字体
			handleFontSize() {
				// 设置网页字体为默认大小
				WeixinJSBridge.invoke('setFontSizeCallback', {
					'fontSize': '12px'
				});
				// 重写设置网页字体大小的事件
				WeixinJSBridge.on('menu:setfont', function() {
					WeixinJSBridge.invoke('setFontSizeCallback', {
						'fontSize': '12px'
					});
				});
			},

			// 初始字体
			initFontSize() {
				if (isWxClient()) {
					if (typeof WeixinJSBridge == "object" && typeof WeixinJSBridge.invoke == "function") {
						this.handleFontSize();
					} else {
						if (document.addEventListener) {
							document.addEventListener("WeixinJSBridgeReady", this.handleFontSize, false);
						} else if (document.attachEvent) {
							document.attachEvent("WeixinJSBridgeReady", this.handleFontSize);
							document.attachEvent("onWeixinJSBridgeReady", this.handleFontSize);
						}
					}
				}

			},

			isWeChat: function() {
				if (isWxClient()) { //判断微信浏览器
					let style = document.createElement('style');
					style.type = 'text/css';
					style.innerHTML = "uni-page-head,.uni-page-head{display:none;}";
					document.getElementsByTagName('head').item(0).appendChild(style);
				}
			},
			// #endif

			// #ifdef MP-TOUTIAO
			/**
			 * desc: 主题色配置
			 * borderRadius：按钮圆角大小，默认 8rpx
			 * backgroundColor：按钮背景色 + 退款原因选中背景色，默认 #FE2C55
			 * fontColor：按钮字体颜色，默认 #ffffff
			 */
			getThemeConfig() {
				return {
					borderRadius: "4rpx",
					backgroundColor: "#2dbb55",
					fontColor: "#ffffff"
				};
			},
			// #endif

			//获取系统数据
			systemInfo() {
				//获取系统信息（满足309,310模板）
				uni.getSystemInfo({
					success: (e) => {
						// this.compareVersion(e.SDKVersion, '2.5.0')
						let statusBar = 0;
						let customBar = 0;

						// #ifdef MP
						statusBar = e.statusBarHeight
						customBar = e.statusBarHeight + 45
						if (e.platform === 'android') {
							customBar = e.statusBarHeight + 50
						}
						// #endif

						// #ifdef MP-WEIXIN
						statusBar = e.statusBarHeight
						const custom = wx.getMenuButtonBoundingClientRect()
						customBar = custom.bottom + custom.top - e.statusBarHeight;
						this.globalData.menuHeight = custom.height; //胶囊高度
						this.globalData.menuBottom = custom.top - statusBar; // 胶囊距底部间距
						// #endif

						// #ifdef MP-ALIPAY
						statusBar = e.statusBarHeight
						customBar = e.statusBarHeight + e.titleBarHeight
						// #endif

						// #ifdef APP-PLUS
						statusBar = e.statusBarHeight
						customBar = e.statusBarHeight + 45
						// #endif

						// #ifdef H5
						statusBar = 0
						customBar = e.statusBarHeight + 45
						// #endif

						this.globalData.stickyHeight = customBar; //状态栏+导航栏高度
						this.globalData.statusBarHeight = statusBar; //状态栏高度
						this.globalData.navBarHeight = customBar - statusBar; //导航栏高度

					}
				});
			},

		}
	}
</script>

<style>
	/*每个页面公共css */
	@font-face {
	  font-family: 'iconfont';  /* Project id 1940415 */
	  src: url('//at.alicdn.com/t/c/font_1940415_115g7dh3b93.woff2?t=1706175121673') format('woff2'),
	       url('//at.alicdn.com/t/c/font_1940415_115g7dh3b93.woff?t=1706175121673') format('woff'),
	       url('//at.alicdn.com/t/c/font_1940415_115g7dh3b93.ttf?t=1706175121673') format('truetype');
	}

	.iconfont {
		display: inline-block;
		font-family: "iconfont" !important;
		font-size: 32rpx;
		font-style: normal;
		-webkit-font-smoothing: antialiased;
		-moz-osx-font-smoothing: grayscale;
	}

	page {
		background-color: #fff;
		color: #333;
		-webkit-user-select: text !important;
	}

	image {
		vertical-align: top;
	}

	.placeholder {
		color: #a9a9a9;
	}

	page button {
		border: none !important;
		border-radius: 0;
	}

	button:after {
		display: none;
	}

	table {
		width: 100% !important;
	}

	input {
		padding: 0;
	}
	/* 取消滚动条 */
	::-webkit-scrollbar{
		width: 0;
		height: 0;
		background-color: transparent;
	}

	/* 重置指示点位置 */
	.credit-banner-block .uni-swiper-dots-horizontal {
		bottom: 48rpx !important;
	}

	/*设置radio的尺寸*/
	.radio-size-base {
		transform: scale(0.8)
	}

	.radio-size-middle {
		transform: scale(1)
	}

	.radio-size-lg {
		transform: scale(1.2)
	}

	/* 列表container绝对定位（避免h5上显示半截） */
	.container-fixed-flex {
		position: absolute;
		top: 0;
		left: 0;
		right: 0;
		bottom: 0;
		overflow: hidden;
	}

	uni-image {
		pointer-events: auto;
	}

	image,
	img {
		vertical-align: middle;
	}
</style>